package com.example.zg.androidnewview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.view.View;

import com.example.zg.androidnewview.adapter.BaseRecycleViewAdapter;
import com.example.zg.androidnewview.customView.MRecyclerView;
import com.example.zg.androidnewview.customView.RectDecoration;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity2 extends AppCompatActivity {
    private MRecyclerView mRecyclerView;
    private BaseRecycleViewAdapter<String> mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view2);
        initRecyclerView();
    }

    private void initRecyclerView(){
        mRecyclerView=findViewById(R.id.recyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this, OrientationHelper.VERTICAL,false));
        mAdapter=new BaseRecycleViewAdapter<String>(initData()) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item2;
            }

            @Override
            public void onBindData(VH holder, String data, int position, int viewType) {
                holder.setText(R.id.text_value,data);

            }
        };

        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.addItemDecoration(new RectDecoration());
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());

        View header=getLayoutInflater().inflate(R.layout.header,null,false);
        View footer=getLayoutInflater().inflate(R.layout.footer,null,false);
        mRecyclerView.addView(header,0);
    }

    private List<String> initData(){
        List<String> list=new ArrayList<>();
        for(int i=0;i<30;i++){
            list.add("item"+i);
        }
        return list;
    }

}
